package edu.hawaii.myisern.sanitycheck;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import edu.hawaii.myisern.collaborations.jaxb.Collaboration;
import edu.hawaii.myisern.organizations.jaxb.Organization;
import edu.hawaii.myisern.researchers.jaxb.Researcher;
/**
 * Item for storing errors.
 * @author John Hauge
 *
 */
public class SanityCheckErrorItem {
  private Object type;
  private String name;
  private List<String> errorList;
  /**
   * Constructor.
   * @param type Researcher, Organization, or Collaboration object. 
   * @param name Name.
   */
  public SanityCheckErrorItem(Object type, String name) {
    this.type = type;
    this.name = name;
    this.errorList = new ArrayList<String>();
  }
  /**
   * Returns the Object.
   * @return Researcher, Organization, or Collaboration String.
   */
  public Object getObject() {
    return this.type;
  }
  /**
   * Returns the Object.
   * @return Researcher, Organization, or Collaboration String.
   */
  public String getType() {
    String type = "";
    if (this.type instanceof Researcher) {
      type = "Researcher";
    }
    else if (this.type instanceof Organization) {
      type = "Organization";
    }
    else if (this.type instanceof Collaboration) {
      type = "Collaboration";
    }
    else {
      type = "Unknown";
    }
    return type;
  }
  /**
   * Returns the Name.
   * @return the Name.
   */
  public String getName() {
    return this.name;
  }
  /**
   * Access to iterate through error list.
   * @return the error list iterator.
   */
  public Iterator<String> getErrorList() {
    return errorList.iterator();
  }
  /**
   * Adds an error string to the error list.
   * @param error error message to add to list.
   */
  public void addError(String error) {
    errorList.add(error);
  }
  /**
   * Returns the number of found errors.
   * @return number of found errors.
   */
  public int getNumErrors() {
    return this.errorList.size();
  }
}
